﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NEWSPAPERINFOMATION
{
    public partial class 用户注册 : Form
    {
        public 用户注册()
        {
            InitializeComponent();
            this.button_sure.Enabled = false;
        }

        DataTable dt = new DataTable();


        private void jc_Click(object sender, EventArgs e)
        {
            BookConnection db = new BookConnection();
            if (this.text_customid.Text.Equals(""))
            {
                MessageBox.Show("用户账号不能为空哦!");
                return;
            }
            else
            {
                String sql = "SELECT * FROM users.Custom WHERE customid='" + this.text_customid.Text + "'";
                dt = db.runSql(sql);
                if (dt.Rows.Count == 0)
                {
                    MessageBox.Show("用户账号可以使用哦!");
                    this.button_sure.Enabled = true;
                    return;
                }
                else
                {
                    MessageBox.Show("用户账号已存在!");
                    return;
                }
            }
        }

        private void button_sure_Click(object sender, EventArgs e)
        {
            if (this.text_customname.Text.Equals(""))
            {
                MessageBox.Show("用户姓名不能为空哦!");
                return;
            }
            else if (this.text_passwd.Text.Equals(""))
            {
                MessageBox.Show("用户姓名不能为空哦!");
                return;
            }
            else if (!(male.Checked || famale.Checked))
            {
                MessageBox.Show("用户性别还没有选择哦!");
                return;
            }
            else
            {
                string sex;
                if (male.Checked)
                {
                    sex = "男";
                }
                else sex = "女";
                String sql = "INSERT INTO users.Custom VALUES('" + this.text_customid.Text + "','" + this.text_customname.Text + "','" + sex + "','" + this.text_age.Text + "','" + this.text_phone.Text + "','" + this.text_address.Text + "','" + this.text_email.Text + "','" + this.text_passwd.Text + "','user')";
                BookConnection db = new BookConnection();
                int j = db.executeSqlResult(sql);
                if (j > 0)
                {
                    MessageBox.Show("添加成功！！");
                    this.text_phone.Text = "";
                    this.text_passwd.Text = "";
                    this.text_customname.Text = "";
                    this.text_customid.Text = "";
                    this.text_address.Text = "";
                    this.text_age .Text= "";
                    this.text_email.Text = "";
                    this.male.Checked = false;
                    this.famale.Checked = false;

                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }


}